﻿/*********************************************************************************
 *Author:         OnClick
 *Version:        1.0
 *UnityVersion:   2018.3.11f1
 *Date:           2019-04-07
 *Description:    IFramework
 *History:        2018.11--
*********************************************************************************/
using UnityEngine;

namespace IFramework
{
    public class ABWWWBundle : ABBundle
    {

        private WWW www;
        public override AssetBundle AB
        {
            get
            {
                if (Err != null) return null;
                return www.assetBundle;
            }
        }

        public override bool IsDone
        {
            get
            {
                if (Err != null) return true;
                if (www.error != null) return true;
                if (www.isDone && www.assetBundle != null) return true;
                return false;
            }
        }


        protected override void OnLoad()
        {
            www = WWW.LoadFromCacheOrDownload(Path, version);
            if (www == null) Err = Path + " LoadFromFileAsync falied.";
        }

        protected override void OnUnLoad()
        {
            if (www != null)
            {
                if (www.assetBundle != null) www.assetBundle.Unload(true);
                www = null;
            }
        }

        public ABWWWBundle(string url, Hash128 hash) : base(url, hash) { }

    }

}
